package com.fire.market.controller;

import com.fire.component.dto.SingleResponse;
import com.fire.component.extension.Assert;

import com.fire.market.product.api.dto.ItemInfo;
import com.fire.market.product.api.result.ItemListResult;
import com.fire.market.product.api.service.ItemQueryFrontService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ProductQueryController
 *
 * @author zwd
 * @date 2021/7/20
 */
@Slf4j
@RestController
@RequestMapping("product/query")
@Api(tags = "商品query操作")
public class ProductQueryController extends BaseController{
    @Reference(timeout = 300)
    ItemQueryFrontService itemQueryFrontService;

    @GetMapping(value = "itemList")
    @ApiOperation(value = "商品的列表", notes = "获取商品列表")
    public SingleResponse<ItemListResult> getItemList(){
        return SingleResponse.of(itemQueryFrontService.getItemList().getData());
    }

    @GetMapping(value = "itemDetail/{itemId}")
    @ApiOperation(value = "商品明细", notes = "获取商品明细")
    @ApiImplicitParam(name = "itemId", value = "商品Id", required = true, dataType = "Integer")
    SingleResponse<ItemInfo> getItemDetail(@PathVariable("itemId") Integer itemId){
        Assert.notNull(itemId, "itemId not null");
        return SingleResponse.of(itemQueryFrontService.getItemDetail(itemId).getData());
    }
}
